<template>
  <div id="Case">
    <vxe-table stripe :data="caseData" style="width: 100%">
      <vxe-table-column title="案件名称" field="caseName" align="center"></vxe-table-column>
      <vxe-table-column title="详细信息" field="caseComment" align="center"></vxe-table-column>
      <vxe-table-column title="代理律师" align="center">
        <template v-slot="{row}">
          {{ lawyerData.find(i => i.id === row.lawyerId).lawyerName }}
        </template>
      </vxe-table-column>
      <vxe-table-column title="案件种类" align="center">
        <template v-slot="{row}">
          {{ caseTypeData.find(i => i.id === row.caseTypeId).caseTypeName || '' }}
        </template>
      </vxe-table-column>
      <vxe-table-column title="状态" align="center">
        <template v-slot="{row}">
          {{ caseStateData.find(i => i.id === row.caseStateId).caseStateName || '' }}
        </template>
      </vxe-table-column>
      <vxe-table-column title="操作" align="center" min-width="140">
        <template v-slot="{row}">
          <el-button size="mini" type="primary" @click="handleCase(row)">处理</el-button>
        </template>
      </vxe-table-column>
    </vxe-table>
    <el-dialog title="选择处理状态" :visible.sync="dialogTableVisible">
      <el-form>
        <el-form-item>
          <el-select v-model="caseStateDialog" clearable>
            <el-option v-for="item in caseStateData" :value="item.id" :label="item.caseStateName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item></el-form-item>
        <el-button type="primary" @click="submitChangeState(caseStateDialog)">确定</el-button>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {listLawyer} from "@/api/Lawyer";
import {listCaseType} from "@/api/caseType";
import {listCaseState} from "@/api/caseState";
import {listMyCase, updateCase} from "@/api/case";

export default {
  name: "Case",
  data() {
    return {
      caseData: [],
      lawyerData: [],
      caseTypeData: [],
      caseStateData: [],
      dialogTableVisible: false,
      caseStateDialog: '',
      tempRow: {}
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      const query = [listLawyer(), listCaseType(), listCaseState(), listMyCase()]
      Promise.all(query).then(res => {
        this.lawyerData = res[0].data.list
        this.caseTypeData = res[1].data.list
        this.caseStateData = res[2].data.list
        this.caseData = res[3].data.list
      })
    },
    handleCase(row) {
      this.dialogTableVisible = true
      this.caseStateDialog = ''
      this.tempRow = row
    },
    submitChangeState(state) {
      if (state === '') {
        this.$message.warning('请选择状态')
      }
      this.dialogTableVisible = false
      this.tempRow.caseStateId = this.caseStateDialog
      updateCase(this.tempRow).then(res => {
        if (res.resultCode === 200) {
          this.$message.success('操作成功')
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
#Case {

}
</style>
